package cn.gson.crmdemo.controller.table;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.gson.crmdemo.model.pojo.Emp;
import cn.gson.crmdemo.model.pojo.Saleslog;
import cn.gson.crmdemo.model.service.PrivilegeService;
import cn.gson.crmdemo.model.service.TableService;
import cn.gson.crmdemo.model.vo.SaleslogVo;

@Controller
public class XieRiZhiController {
	/**
	 * 添加日志
	 */
	@Autowired
	TableService ts;
	@Autowired
	PrivilegeService ps;
	/**
	 * 新增日志
	 */
	@RequestMapping("add-journal")
	public String addJournal(String content,HttpServletRequest request) {
		Emp emp = (Emp) request.getSession().getAttribute("emp");
		ps.addJournal(content, emp.getEmpId());
		return "redirect:emp-journal";
	}
	/**
	 * 查询日志
	 * @return
	 */
	@RequestMapping("log-json")
	@ResponseBody
	public Map<String, Object> logjson(Integer page,Integer pageSize) {
		Page<Object> pages = PageHelper.startPage(page, pageSize);
		JSONArray list = ts.adclong();
		long total = pages.getTotal();
		Map<String, Object> map = new HashMap<>();
		map.put("list", list);
		map.put("total", total);
		return map;
	}
	/**
	 * 删除日志
	 */
	@RequestMapping("log")
	public String shanchu(Integer id) {
		System.err.println(id);
		 ts.shanchu(id);
		 return "redirect:log-json?page=1&pageSize=4";
	}
}
